package com.atguigu.cloud.controller;/**
 * @Auter zzh
 * @Date 2024/11/13
 */

import com.atguigu.cloud.entities.Admin;
import com.atguigu.cloud.entities.Order;
import com.atguigu.cloud.sevice.Impl.AdminServiceImpl;
import com.atguigu.cloud.tool.load.page.PaginationResult;
import com.atguigu.cloud.tool.resp.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @projectName: keshe
 * @package: com.atguigu.cloud.controller
 * @className: admincontrollor
 * @author: Eric
 * @description: TODO
 * @date: 2024/11/13 18:14
 * @version: 1.0
 */
@RestController
@Tag(name = "管理员模块", description = "管理员增删改")
public class Admincontrollor {
    @Resource
    AdminServiceImpl adminService;
    //增加管理员

    @PostMapping(value = "/admin/add")
    @Operation(summary = "添加管理员", description = "添加管理员")
    public ResultData<String> addadmin(@RequestBody Admin admin){
        System.out.println(admin.toString());
        int i = adminService.add(admin);
        return ResultData.success("成功插入记录，返回值："+i);
    }
    //删除管理员
    @DeleteMapping(value = "/admin/del/{id}")
    @Operation(summary = "删除管理员", description = "删除管理员")
    public ResultData<String> deleteadmin(@PathVariable("id") Integer id) {
        Integer i=adminService.delete(id);
        return ResultData.success("成功删除记录，返回值："+i);
    }

    //修改管理员
    @PutMapping(value = "/admin/update")
    @Operation(summary = "修改管理员", description = "修改管理员")
    public ResultData<String> updateadmin(@RequestBody Admin admin){
        int i = adminService.update(admin);
        return ResultData.success("成功修改记录，返回值："+i);
    }
    //查询管理员
    @GetMapping(value = "/admin/get/{id}")
    @Operation(summary = "查询管理员", description = "查询管理员")
    public ResultData<Admin> getById(@PathVariable("id") Integer id){
        Admin admin=adminService.getById(id);
        return ResultData.success(admin);
    }
    //查询所有管理员
    @GetMapping(value = "/admin/getall")
    @Operation(summary = "查询所有管理员", description = "查询所有管理员")
    public ResultData<List<Admin>> getAll(){
        return ResultData.success(adminService.getAll());
    }

    //分页查询所有订单
    @GetMapping(value = "/admin/paginationQuery/getall/{currentPage}")
    @Operation(summary = "分页的进行管理员的查询", description = "分页的进行管理员的查询")
    public ResultData<PaginationResult<Admin>> paginationQuery(@PathVariable("currentPage") Integer currentPage){
        return ResultData.success(adminService.myPaginationQuery(currentPage));
    }
}
